package org.example.managere.entity.feibiao;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.util.Date;

/**
 * 电机适用标准关联表实体类
 * 用于记录电机与各类标准的符合关系
 */
@Entity
@Table(name = "am_archives_relation", 
       uniqueConstraints = @UniqueConstraint(name = "uq_motor_standard", columnNames = {"motor_id", "standard_type"}),
       indexes = {
           @Index(name = "idx_standard_type", columnList = "standard_type"),
           @Index(name = "idx_standard_value", columnList = "standard_value"),
           @Index(name = "idx_relation_date", columnList = "relation_date")
       }
)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AmArchivesRelation {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "relation_id", nullable = false)
    private Integer relationId;
    
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "motor_id", nullable = false, 
                foreignKey = @ForeignKey(name = "fk_relation_motor_id"))
    private AmArchivesBase motorId;
    
    @Column(name = "standard_type", nullable = false, length = 50, 
            columnDefinition = "varchar(50) COMMENT '标准分类(功率密度/能效等级等)'")
    private String standardType;
    
    @Column(name = "standard_value", nullable = false, length = 50, 
            columnDefinition = "varchar(50) COMMENT '标准阈值(如≥2kW/kg)'")
    private String standardValue;
    
    @Column(name = "relation_date")
    @Temporal(TemporalType.DATE)
    private Date relationDate;
    
    @Column(name = "remarks", length = 500)
    private String remarks;
    
    @Column(name = "created_at")
    @CreationTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;
    
    @Column(name = "updated_at")
    @UpdateTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;
} 